package org.jmc.refmanager.web.wicket.form;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.PropertyModel;
import org.jmc.refmanager.domain.model.Change.Operation;
import org.jmc.refmanager.web.wicket.markup.html.form.ChoiceRenderer.EnumDropDownChoice;

public abstract class ChangeSearchForm extends Form<String> {
	private static final long serialVersionUID = 1L;

	private Operation operation = null;//Operation.CREATE;

	protected abstract void onSubmit(PageParameters params);

	/**
	 * 
	 * @param id
	 */
	public ChangeSearchForm(String id) {
		super(id);

		EnumDropDownChoice<Operation> operationChoice = new EnumDropDownChoice<Operation>("operation", 
				new PropertyModel<Operation>(this, "operation"), Operation.class);
		// set null = "" in property file (remove "" properties file)
		operationChoice.setNullValid(true);
		add(operationChoice);
		
		Button btnSearch = new Button("btnSearch");
		add(btnSearch);
	}

	@Override
	protected void onSubmit() {
		PageParameters params = new PageParameters();
		if (getOperation() != null) {
			params.add("operation", getOperation().name());
			this.onSubmit(params);
		} else {
			this.onSubmit(params);
		}
	}

	/**
	 * @return the operation
	 */
	public Operation getOperation() {
		return operation;
	}

}
